<?php
include('db.php');
$db = getDb();

$content="";


if($_GET["a"] == "getEvents")
{
	$sqlCommand="SELECT id,name FROM event";
	$result = $db->Execute($sqlCommand);
	
	if ($result === false)
		die($sqlCommand);
	
	while (!$result->EOF)
	{
		$content.= "<li><input type=\"submit\" value=\"X\" onclick=\"removeEvent(".$result->fields[0] . ")\">  ".
				"<a href=\"subevent.php?id=". $result->fields[0] .
				"\">" . $result->fields[1] . "</a></li>\n";
	
		$result->MoveNext();
	}
	
}

if($_GET["a"] == "addEvent")
{
	$sqlCommand="INSERT INTO event(name) values('".
			$_GET["name"] . "') ";
	$result = $db->Execute($sqlCommand);

	if ($result === false)
		die($sqlCommand);
}

if($_GET["a"] == "removeEvent")
{
	$sqlCommand="DELETE FROM event WHERE id=". $_GET["id"];
	$result = $db->Execute($sqlCommand);

	if ($result === false)
		die($sqlCommand);
}

echo $content;

?>